//发送验证码
let code = document.querySelector('.code')
code.addEventListener('click', function () {
    this.innerHTML = `10秒后重新获取` 
    let num = 10
    var timer = setInterval(function () {
        num--
        code.innerHTML = `0${num}秒后重新获`
        if (num === 0) {
              code.innerHTML=`请重新获取`
        clearInterval(timer)
    }
    },1000)
  
    })
//手机号验证
      // 正则 /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/
      let phone = document.querySelector('[name=phone]')
      phone.addEventListener('change', verifyPhone)
      function verifyPhone() {
        let span = phone.nextElementSibling
        let reg = /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/
        if (!reg.test(phone.value)) {
          span.innerHTML = '请输入11位数字'
          return false
        }
        span.innerHTML = ''
        return true
}
//短信验证码
  //验证码/^\d{6}$/
  let codeInput = document.querySelector('input[name=code]')
  codeInput.addEventListener('change', verifyCode)
  function verifyCode() {
    let span = codeInput.nextElementSibling
    let reg = /^\d{6}$/
    if (!reg.test(codeInput.value)) {
      // console.log('wrong');
      span.innerHTML = '请输入6位数字'
      return false
    }
    span.innerHTML = ''
    return true
}
//登录按钮
let btn = document.querySelector('button')
btn.addEventListener('click', function (e) {
    e.preventDefault()
    let obj = {
        phone: phone.value,
        codeInput:codeInput.value,
    }
    localStorage.setItem('key', JSON.stringify(obj))
    location.href='./index.html'  
})
  

